# -*- coding: utf-8 -*-#
'''
# Name:         TrainingHistory_1_0
# Description:  记录训练过程中的训练历史
# Author:       super
# Date:         2020/5/8
'''

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

"""
Version 1.0
- to record the history of training loss and weights/bias value
- can show the plotting
"""
class TrainingHistory_1_0(object):
    def __init__(self):
        self.iteration = []
        self.loss_history = []
        self.w_history = []
        self.b_history = []

    def AddLossHistory(self, iteration, loss, w, b):
        self.iteration.append(iteration)
        self.loss_history.append(loss)
        self.w_history.append(w)
        self.b_history.append(b)

    def ShowLossHistory(self, params, xmin=None, xmax=None, ymin=None, ymax=None):
        plt.plot(self.iteration, self.loss_history)
        title = params.toString()
        plt.title(title)
        plt.xlabel("iteration")
        plt.ylabel("loss")
        if xmin != None and ymin != None:
            plt.axis([xmin, xmax, ymin, ymax])
        plt.show()
        return title

    def GetLast(self):
        count = len(self.loss_history)
        return self.loss_history[count-1], self.w_history[count-1], self.b_history[count-1]